package com.gma.userprofile.behavior.commodity

import com.gma.userprofile.util.{HBaseUtil, SparkUtil}

object UserProfileFavGoods {
  def main(args: Array[String]): Unit = {
    //获取分区参数
    val ds = args.head

    //获取spark环境
    val spark = SparkUtil.getSparkSession

    //提取标签
    val tah = spark.sql(
      s"""
         |
         |-- collect_set: 将组内的数据聚会成一个数组，去重
         |-- collect_list: 将组内的数据聚会成一个数组，不去重
         |-- concat_ws： 将数组拼接成字符串
         |select
         |    a.member_id as id,
         |    concat_ws(',',collect_set(b.commodity_id)) as favGoods
         |from
         |    (
         |        select
         |            *
         |        from
         |            dwd.dwd_order_info_d_f
         |        where
         |            ds = '$ds'
         |    ) as a
         |    join (
         |        select
         |            *
         |        from
         |            dwd.dwd_order_commodity_info_d_f
         |        where
         |            ds = '$ds'
         |    ) as b on a.order_id = b.order_id
         |group by a.member_id
         |
         |""".stripMargin)

    //保存到hbase
    HBaseUtil.tagToHBase(tah, "favGoods")

  }
}
